﻿@{
    ViewBag.Title = "农业产业化龙头企业季报";
    Layout = "~/Views/Shared/_LayoutChild.cshtml";
}
@section head {
    @if (false)
    {<script src="~/Scripts/jquery-1.6.4-vsdoc.js" type="text/javascript"></script>}
    @Html.Partial("_JqGrid")
    <script type="text/javascript"
     src="@Url.Content("~/Scripts/jquery.uploadify-3.1.js")"  ></script>
    <link href="@Url.Content("~/Content/uploadify/uploadify.css")"     rel="stylesheet" type="text/css" />
    <style type="text/css">
        table, table td, table th
        {
            border-collapse: collapse;
            font-size: 12px;
        }
        table
        {
            table-layout: fixed;
        }
        td
        {
            white-space: nowrap;
            display: table-cell;
            vertical-align: inherit;
        }
        .uploadify
        {
            margin-top: 4px;
            padding-top: 3px;
            padding-bottom: 0px;
            margin-bottom: 0px;
            border: #ccc 1px solid;
        }
        .uploadify-button
        {
            background-color: transparent;
            border: none;
            padding: 0;
        }
        .uploadify:hover .uploadify-button
        {
            background-color: transparent;
            border: none;
            padding: 0;
            margin-top: -6px;
        }
        .uploadbtn
        {
            width: 40px;
            height: 20px;
            background-color: transparent;
            border: none;
            padding: 0;
        }
        .uploadify-queue
        {
            left: 1px;
            top: 1px;
            width: 40px;
        }
    </style>
    <script language="javascript" type="text/javascript">
        var selectId = "";
        var gridId = "#tableId";
        var edittype = '@ViewBag.edittype'; //0不可编辑，1可编辑
        var colModels = "";
        var saveUrl = '/DataManage/Report/SaveNYCYHLTQYJB/';
        var organization_type = '@ViewBag.Organization.Organization_Type';
        var organization_name = '@ViewBag.Organization.Organization_Name';
        $(document).ready(function () {
            funGridInit();
            colModels = JSON.stringify($(gridId).getGridParam('colModel'));
            initUpload();
            if (edittype == "0") {
                $("#btnImport").css('display', 'none');
                $("#addRow").css('display', 'none');
                $("#delRow").css('display', 'none');
                $("#funSave").css('display', 'none');

            }
            //如果是龙头企业，则不能手动添加行，系统将自动为其添加一行
            if (organization_type == '1') {
                $("#addRow").css('display', 'none');
                $("#delRow").css('display', 'none');
                $("#ChooseExportType").css('display', 'none');
            }

            $("#titlediv").html( " 报表ID:" + '@ViewBag.SubmitInfoId' );
    
        });
        function initUpload() {
            $("#btnImport").uploadify({
                'formData': { 'ASPSESSID': '@(Session.SessionID)', 'AUTHID': '@ViewBag.auth', GUID: '@ViewBag.GUID', 'submitInfoId': '@ViewBag.SubmitInfoId', 'colModels': colModels },
                'multi': false,
                'auto': true,
                'swf': '/Content/uploadify/uploadify.swf',
                'uploader': '/DataManage/Report/importReportExB',
                'width': 60,
                'fileTypeExts': '*.xls',
                'height': 22,
                'buttonImage': '/Content/import.png',
                'onSelect': function (e, queueId, fileObj) { parent.$.cover(true); }, //选择文件后触发的事件。
                'onUploadSuccess': function (file, data, response) {
                    var d = $.parseJSON(data);
                    if (d.ErrorMessage == null || d.ErrorMessage.length == 0) {
                        //                        $(gridId).clearGridData(); //清空表中原有数据。
                        var thegrid = $(gridId)[0];
                        thegrid.addJSONData(d); //将数据填充到grid中
                        //如果是龙头企业导入，则只能导入一行数据。
                        if (organization_type == '1' && $(gridId).jqGrid('getGridParam', 'reccount') > 1) {
                            top.asyncbox.alert('龙头企业只允许导入一行数据!', '提示');
                            Search(); //重新加载grid
                            parent.$.cover(false);
                            return;
                        }

                        //保存一下数据
                        $.funDetailSave('formDetail', gridId, saveUrl, function (d) {
                            parent.$.cover(false);
                            if (d == null || d.ErrorMessage.length == 0) {
                                // top.asyncbox.tips('导入数据成功!', 'success');//注释掉该行的原因是，funDetailSave里面已经有提示，故此处不需要再提示
                            }
                            else
                                top.asyncbox.alert('导入数据失败!', '提示');
                        });

                    }
                    else {
                        parent.$.cover(false);
                        top.asyncbox.alert('导入数据失败,失败原因：' + d.ErrorMessage, '提示');
                    }
                }
            });
        }

        function Search() {
            //查询
            $(gridId).setGridParam({ page: 1 });
            $(gridId).trigger("reloadGrid");
        }
        function funGridInit() {
            //初始化表格
            var option = {
                height: $("#divGridContainer").height() - 71,
                width: $("#divGridContainer").width() - 3,
                url: '',
                autowidth: false,
                multiselect: true,
                rowNum: 1000,
                cellEdit: true,
                url: '/DataManage/Report/NYCYHLTQYJB_GetList/@ViewBag.SubmitInfoID',
                cellsubmit: 'clientArray',
                datatype: "json", //local
                sortname: 'SubmitInfoID',
                sortorder: 'desc',
                shrinkToFit: false,
                sortable: false,
                colModel: [
                { label: '企业名称', name: 'QYMC', notnull: true, width: 150, editable: true, edittype: 'text' },
                { label: '累计', name: 'XSSR_LJ', width: 60, sortable: false, editable: true, align: "right", formatter: 'snNumber', edittype: 'text' },
                { label: '±%', name: 'XSSR_JJ', width: 60, sortable: false, editable: true, align: "right", formatter: 'snNumber', edittype: 'text' },
                { label: '累计', name: 'ZJZ_LJ', width: 60, sortable: false, editable: true, align: "right", formatter: 'snNumber', edittype: 'text' },
                { label: '±%', name: 'ZJZ_JJ', width: 60, sortable: false, editable: true, align: "right", formatter: 'snNumber', edittype: 'text' },
                { label: '累计', name: 'LRZE_LJ', width: 60, sortable: false, editable: true, align: "right", formatter: 'snNumber', edittype: 'text' },
                { label: '±%', name: 'LRZE_JJ', width: 60, sortable: false, editable: true, align: "right", formatter: 'snNumber', edittype: 'text' },
                { label: '累计', name: 'SJSJ_LJ', width: 60, sortable: false, editable: true, align: "right", formatter: 'snNumber', edittype: 'text' },
                { label: '±%', name: 'SJSJ_JJ', width: 60, sortable: false, editable: true, align: "right", formatter: 'snNumber', edittype: 'text' },
                { label: '累计', name: 'CKCH_LJ', width: 100, sortable: false, editable: true, align: "right", formatter: 'snNumber', edittype: 'text' },
                { label: '±%', name: 'CKCH_JJ', width: 100, sortable: false, editable: true, align: "right", formatter: 'snNumber', edittype: 'text' },
                { label: '总人数', name: 'ZGRS_LJ', width: 100, sortable: false, editable: true, align: "right", formatter: 'intFmatter', edittype: 'text' },
                { label: '其中农村劳动力', name: 'ZGRS_JJ', width: 100, sortable: false, editable: true, align: "right", formatter: 'intFmatter', edittype: 'text' },
                { label: '累计', name: 'LDZBC_LJ', width: 100, sortable: false, editable: true, align: "right", formatter: 'snNumber', edittype: 'text' },
                { label: '±%', name: 'LDZBC_JJ', width: 100, sortable: false, editable: true, align: "right", formatter: 'snNumber', edittype: 'text' },
                { label: '累计', name: 'GDZCTZ_LJ', width: 100, sortable: false, editable: true, align: "right", formatter: 'snNumber', edittype: 'text' },
                { label: '±%', name: 'GDZCTZ_JJ', width: 100, sortable: false, editable: true, align: "right", formatter: 'snNumber', edittype: 'text' },
                { label: '小计', name: 'ZSYZ_XJ', width: 100, sortable: false, editable: true, align: "right", formatter: 'snNumber', edittype: 'text' },
                { label: '其中内资', name: 'ZSYZ_NZ', width: 100, sortable: false, editable: true, align: "right", formatter: 'snNumber', edittype: 'text' },
                { label: '其中外资', name: 'ZSYZ_WZ', width: 100, sortable: false, editable: true, align: "right", formatter: 'snNumber', edittype: 'text' },
                { label: '±%', name: 'ZSYZ_JJ', width: 100, sortable: false, editable: true, align: "right", formatter: 'snNumber', edittype: 'text' },
                { label: '累计', name: 'YHDK_LJ', width: 100, sortable: false, editable: true, align: "right", formatter: 'snNumber', edittype: 'text' },
                { label: '其中农发行', name: 'YHDK_NFH', width: 100, sortable: false, editable: true, align: "right", formatter: 'snNumber', edittype: 'text' },
                { label: '小计', name: 'JDJS_XJ', width: 100, sortable: false, editable: true, align: "right", formatter: 'snNumber', edittype: 'text' },
                { label: '其中自建基地', name: 'JDJS_ZJJD', width: 100, sortable: false, editable: true, align: "right", formatter: 'snNumber', edittype: 'text' },
                { label: '其中联系基地', name: 'JDJS_LXJD', width: 100, sortable: false, editable: true, align: "right", formatter: 'snNumber', edittype: 'text' },
                { label: '带动农户（半年）', name: 'LXNH', width: 60, sortable: false, editable: true, align: "right", formatter: 'snNumber', edittype: 'text' },
                { name: 'SubmitInfoID', formatter: 'snNumber', hidden: true }
   	            ],
                onSelectRow: function (rowid, cellname, value, iRow, iCol) {
                    _rowId = rowid;
                },
                ondblClickRow: function (rowid) {
                    _rowId = rowid;
                },
                afterSaveCell: function (rowid, cellname, value, iRow, iCol, flag) {
                    $.goToNextCell(gridId, iRow, iCol, false);
                },
                beforeRequest: function (d) {
                },
                gridComplete: function () {
                    //如果是龙头企业,并且没有录入过数据 ，则自动插入一行,并将企业
                    if (organization_type == '1' && edittype == "1" && $(gridId).jqGrid('getGridParam', 'reccount') == 0) {
                        addRow();
                        $(gridId).setCell(1, "QYMC", organization_name);
                    }
                }
            };
            var o = jqGridHelper.getConfig("#pageId", option);
            $(gridId).jqGrid(o);
            $(gridId).jqGrid('setGroupHeaders', {
                useColSpanStyle: true,
                groupHeaders: [
	               { startColumnName: 'XSSR_LJ', numberOfColumns: 2, titleText: '营业收入' },
                   { startColumnName: 'ZJZ_LJ', numberOfColumns: 2, titleText: '增加值' }, //
                   {startColumnName: 'LRZE_LJ', numberOfColumns: 2, titleText: '利润总额' },
                   { startColumnName: 'SJSJ_LJ', numberOfColumns: 2, titleText: '实交税金' }, //CKCH_LJ
                   {startColumnName: 'CKCH_LJ', numberOfColumns: 2, titleText: '出口创汇(万美元)' },
                   { startColumnName: 'ZGRS_LJ', numberOfColumns: 2, titleText: '职工人数（人）（季度）' },
                   { startColumnName: 'LDZBC_LJ', numberOfColumns: 2, titleText: '劳动者报酬（季度）' },
                   { startColumnName: 'GDZCTZ_LJ', numberOfColumns: 2, titleText: '固定资产投资（季度）' }, //
                   {startColumnName: 'ZSYZ_XJ', numberOfColumns: 4, titleText: '招商引资（季度）' }, //
                   {startColumnName: 'YHDK_LJ', numberOfColumns: 2, titleText: '银行贷款（半年）' }, //JDJS_XJ
                   {startColumnName: 'JDJS_XJ', numberOfColumns: 3, titleText: '基地建设' }
                ]
            });
        }
        function loadGrid() {
            $(gridId).trigger("reloadGrid");
        }
        function funSave() {
            $.funDetailSave('formDetail', gridId, saveUrl, function (d) {
            });
        }

        function addRow() {
            var _rownum = $(gridId).getDataIDs().length + 1;
            var _data = { SubmitInfoID: '@ViewBag.SubmitInfoID' };
            $(gridId).addRowData(_rownum, _data);
        }

        function delRow() {
            jqGridHelper.delSelRows(gridId);
        }

        function ExportReport() {
            //农业产业化龙头企业季报
            //如果Organization_Level为0，则显示全部，传过去的参数为""值
            var url = '/DataManage/Report/ExportNYCYHLTQYJBReport/@ViewBag.SubmitInfoID' + '?Organization_Level=' + ($("input[name='Organization_Level']:checked").eq(0).val() == '0' ? "" : $("input[name='Organization_Level']:checked").eq(0).val())
            window.location.href =url;
        }
    </script>
}
<div class="ui-layout-north" id='toolbar'>
    <div id="titlediv" class="headertitle">
    </div>
    <div style="float: right; margin-right: 20px; margin-top: 2px; line-height: 32px;">
        <div style="float: left;">
            <input type="file" name="btnImport" id="btnImport" class=" padding-top: 10px;" />
        </div>
        <a onclick="addRow();" class="button green" id="addRow"><span class="icon-botton"
            style="background: url('/Content/16/hj.png') no-repeat scroll 0px 4px;"></span>新增</a>&nbsp;<a
                onclick="delRow();" class="button green" id="delRow"><span class="icon-botton" style="background: url('/Content/16/hj.png') no-repeat scroll 0px 4px;"></span>删除</a>&nbsp;
        <a onclick="funSave();" class="button green" id="funSave"><span class="icon-botton"
            style="background: url('/Content/16/hj.png') no-repeat scroll 0px 4px;"></span>保存</a>
    </div>
    <div style="float: right; margin-right: 5px; margin-top: 2px; line-height: 32px;">
        <div id="ChooseExportType" style="float: left;">
        <label>
            仅导出：</label>
        <input id="Organization_Level" name="Organization_Level" type="radio" value="0" checked="checked"/><label>全部</label>&nbsp;
        <input id="Organization_Level" name="Organization_Level" type="radio" value="1" /><label>国家级</label>&nbsp;
        <input id="Organization_Level" name="Organization_Level" type="radio" value="2" /><label>省级</label>&nbsp;
        <input id="Organization_Level" name="Organization_Level" type="radio" value="3" /><label>市级</label>
        </div>
        <div style="float: left;">
        <a onclick="ExportReport();" class="button green"><span class="icon-botton" style="background: url('/Content/16/hj.png') no-repeat scroll 0px 4px;">
        </span>导出</a>
        </div>
    </div>
</div>
</div>
<div id="divGridContainer" class="ui-layout-center" style="overflow: hidden;">
    <form id="formData" method="post">
    </form>
    <table id="tableId">
    </table>
    <div id="pageId">
    </div>
</div>
